
class ChatMessage {
  String role;
  String content;
  // pr

  ChatMessage({required this.role, required this.content});
  ChatMessage.formJson(Map<String, dynamic> json)
      : content = json['content'],
        role = json['role'];
  static List<ChatMessage> formListJson(List<dynamic>? jsonList) {
    List<ChatMessage> msgList = [];
    if (jsonList != null && jsonList.isNotEmpty) {
      for (var element in jsonList) {
        msgList.add(ChatMessage.formJson(element));
      }
    }
    return msgList;
  }

  toJson() {
    return {"role": role, "content": content};
  }

  static toListJson(List<ChatMessage> msgList) {
    List<Map<String, dynamic>> jsonList = [];
    if (msgList.isNotEmpty) {
      for (var element in msgList) {
        jsonList.add(element.toJson());
      }
    }
    return jsonList;
  }

  @override
  String toString() {
    // TODO: implement toString
    return "{role:$role, content:$content}";
  }
}
